package tclp;

import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import net.sourceforge.javaocr.ocrPlugins.mseOCR.TrainingImage;
import org.jnativehook.keyboard.NativeKeyEvent;

/**
 *
 * @author Absatz Leoš
 */
public class SettingsLoader {

  public static NativeKeyEvent loadActivationKey(Settings settings) {
    try {
      File settingsFile = new File(settings.getActivationKeySettings());
      ObjectInputStream inputStream = new ObjectInputStream(new FileInputStream(settingsFile));
      NativeKeyEvent e = (NativeKeyEvent) inputStream.readObject();
      inputStream.close();
      return e;
    } catch (Exception ex) {
      System.out.println(ex);
      return null;
    }
  }

  public static String loadScreenCoords(Settings settings) {
    try {
      File file = new File(settings.getScreenSettings());
      BufferedReader reader = new BufferedReader(new FileReader(file));
      String line = reader.readLine();
      reader.close();
      return line;
    } catch (Exception ex) {
      System.out.println(ex);
      return null;
    }
  }

  public static HashMap<Character, ArrayList<TrainingImage>> loadTrainingImages(Settings settings) {
    try {
      File trainingImagesFile = new File(settings.getTrainingImages());
      ObjectInputStream inputStream = new ObjectInputStream(new FileInputStream(trainingImagesFile));
      HashMap<Character, ArrayList<TrainingImage>> hashMap = (HashMap<Character, ArrayList<TrainingImage>>) inputStream.
          readObject();
      inputStream.close();
      return hashMap;
    } catch (Exception ex) {
      System.out.println(ex);
      return null;
    }
  }
  
  public static String loadFrapsScreenshotPath(Settings settings) {
    try {
      File file = new File(settings.getFrapsPathSettings());
      BufferedReader reader = new BufferedReader(new FileReader(file));
      String line = reader.readLine();
      reader.close();
      return line;
    } catch (Exception ex) {
      System.out.println(ex);
      return null;
    }  
  }
  
  public static String loadOutputFilePath(Settings settings) {
    return settings.getOutputFile();
  }
}
